<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择支出合同结算信息</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">结算类型：</label>
                        <div class="layui-input-block">
                            <select id="jietype" name="jietype" lay-filter="jietype">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">合同类型：</label>
                        <div class="layui-input-block">
                            <select id="caitype" name="caitype" lay-filter="caitype">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">供应方(乙方)</label>
                        <div class="layui-input-block">
                            <input type="text" name="gonger" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">结算主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">结算单号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">结算日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="jiedt" placeholder="请输入" autocomplete="off" class="layui-input bdate_sea_range_ymd">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="enginid" name="enginid">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>


<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');

    var parent_gonger = getQueryVariable('gonger') || '';
    parent_gonger = decodeURIComponent(parent_gonger);
    if(parent_gonger){
        $("#gonger").attr('disabled','disabled');
    }


    var parent_enginid = getQueryVariable('enginid') || 0;
    var parent_caitype = getQueryVariable('caitype') || '';
    if(parent_caitype){
        $("#caitype").prop('disabled',true);
    }

    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_opt_get_contract_cai_jie),where: {enginid:parent_enginid,caitype:parent_caitype,gonger:parent_gonger}, page: true
            , height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: ['', '', ''],filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,parseData: function(res){
                xiala_zhan_one_you('jietype', res.data.jietype, res.data.is_jietype)
                xiala_zhan_one_zuo('caitype', res.data.caitype, res.data.is_caitype)
                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            ,cols: [[
                {type:choose_type,fixed:'left'}
                ,{field:'enginname',title:'项目名称',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../engin/show.php?id='+d.enginid+'\')">'+d.enginname+'</span>';
                    }}
                ,{field: 'business_name', title: '项目属性'}
                ,{field:'cainame',title:'支出合同名称',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../contract_cai/show.php?id='+d.caiid+'\')">'+d.cainame+'</span>';
                    }}
                ,{field: 'caitype_name', title: '合同类型'}
                ,{field: 'gonger', title: '合同供应方'}
                ,{field:'number',title:'结算单号',templet: function(d){
                        return '<span class="colorlan" onclick="openPage(\'../contract_cai_jie/show.php?id='+d.id+'\')">'+d.number+'</span>';
                    }}
                ,{field: 'jietype', title: '结算类型'}
                ,{field: 'title', title: '结算主题'}
                ,{field: 'money', title: '本次结算金额(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.money);}}
                ,{field: 'koufafee', title: '扣罚款金额(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.koufafee);}}
                ,{field: 'jingfee', title: '结算净额(元)',align:'right',totalRow: true,templet: function(d){return parseFormatNum(d.jingfee);}}
                ,{field: 'jiedt', title: '结算日期'}
            ]]
            ,done : function(res, curr, count){
                $(".layui-table-tool").remove()
                soulTable.render(this);
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = layui.table.checkStatus('datalist');
            var data = checkStatus.data;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }

            if(parent_page == '页面值'){

            }else if(parent_page == 'zhi_xiang'){
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'
                    +'支出合同结算单-(金额：'+data[0].jingfee+')'+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

                $("#duierzhan" , parent.document).val(data[0].gonger);
                $("#duier" , parent.document).html('');
                var duier_str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].gonger+'"><span class="choose_content">'+data[0].gonger+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \'duier\')">×</span></button>';
                $("#duier" , parent.document).html(duier_str);
                parent.formValid('duier');

                if(data[0].gonger_info){
                    var bankstr = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].gonger_info.banknum+'"><span class="choose_content">'+data[0].gonger_info.banknum+'' +
                        '</span><span class="choose_close" onclick="choose_close(this, \'banknum\')">×</span></button>';
                    $("#banknum" , parent.document).html(bankstr);
                    parent.formValid('banknum');
                    $("#bankname" , parent.document).val(data[0].gonger_info.bankname);
                }
            }else{

            }

            layer_close();
        });

    });
</script>
</body>
</html>
